//
//  OpenAnimationView.m
//  RPay
//
//  Created by hzy on 2017/11/2.
//  Copyright © 2017年 Charlie. All rights reserved.
//

#import "OpenAnimationView.h"

@implementation OpenAnimationView

-(void)awakeFromNib{

    [super awakeFromNib];
    _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeFromSuperview)];
    
    [self addGestureRecognizer:_tap];
}
- (IBAction)openBtnClick:(UIButton *)sender {
    
    if (self.openBlock) {
        self.openBlock();
    }
    sender.userInteractionEnabled = NO;
    
    [self removeGestureRecognizer:_tap];
    
    [self ActionFanzhuan];
    
}

-(void)ActionFanzhuan{
    
    //获取当前画图的设备上下文
    
    CGContextRef context =UIGraphicsGetCurrentContext();
    
    //开始准备动画
    
    [UIView beginAnimations:nil context:context];
    
    //设置动画曲线，翻译不准，见苹果官方文档
    
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    
    //设置动画持续时间
    
    [UIView setAnimationDuration:.4];
    
    //因为没给viewController类添加成员变量，所以用下面方法得到viewDidLoad添加的子视图
    

    
    //设置动画效果
    
    //    [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES];  //从上向下
    
    // [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES];   //从下向上
    
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.openBtn cache:YES];//从左向右
    
    //     [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES];//从右向左
    
    //设置动画委托
    
    [UIView setAnimationDelegate:self];
    
    //当动画执行结束，执行animationFinished方法
    
    [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    
    //提交动画
    
    [UIView commitAnimations];
    
}

//动画效果执行完毕

- (void) animationFinished: (id) sender{
    

    
    NSLog(@"animationFinished !");
    [self ActionFanzhuan];
    
}




@end
